// define(['routes','services/dependencyResolverFor'], function(config, dependencyResolverFor)
// {
//     var app = angular.module('app', [
//         'ngRoute',
//         'ngAnimate',
//         'ngSanitize',
//         'ngResource',
//         'ui.router',
//         'anGrid',
//         'ui.bootstrap',
//         'app.directives',
//         'app.localization',
//         'app.filter',//@todo delete
//         'app.task' //@todo delete
//     ]);

//     app.config(
//     [
//         '$routeProvider',
//         '$locationProvider',
//         '$controllerProvider',
//         '$compileProvider',
//         '$filterProvider',
//         '$provide',
//         '$stateProvider',
//         '$urlRouterProvider',

//         function($routeProvider, $locationProvider, $controllerProvider, $compileProvider, $filterProvider, $provide)
//         {
// 	        app.controller = $controllerProvider.register;
// 	        app.directive  = $compileProvider.directive;
// 	        app.filter     = $filterProvider.register;
// 	        app.factory    = $provide.factory;
// 	        app.service    = $provide.service;

//             $locationProvider.html5Mode(true);

//             if(config.routes !== undefined)
//             {
//                 angular.forEach(config.routes, function(route, path)
//                 {
//                     $routeProvider.when(path, {templateUrl:route.templateUrl, resolve:dependencyResolverFor(route.dependencies)});
//                 });
//             }

//             if(config.defaultRoutePaths !== undefined)
//             {
//                 $routeProvider.otherwise({redirectTo:config.defaultRoutePaths});
//             }
//         }
//     ]).controller('AppCtrl', [
//         '$scope', '$location', function($scope, $location) {
//             $scope.main = {
//                 brand: 'AnguarJs小练习'
//             };
//             // console.log("dsddsdfsf");
//         }
//     ]);

//    return app;
// });
define([
    'routes',
    'Common/services/dependencyResolverFor',
    'Common/directives/app-directives',
    'Common/directives/app-localize',
    'Common/filter/app-filter', //@todo delete
    'Common/factorys/Task' //@todo delete
], function(
    config,
    dependencyResolverFor
    ){

    var app = angular.module('app', [
        'ngRoute',
        'ngAnimate',
        'ngSanitize',
        'ngResource',
        'ui.router',
        'anGrid',
        'ui.bootstrap',
        'app.directives',
        'app.localization',
        'app.filter',//@todo delete
        'app.task' //@todo delete
    ]).config([
        '$routeProvider',
        '$locationProvider',
        '$controllerProvider',
        '$compileProvider',
        '$filterProvider',
        '$provide',
        '$stateProvider',
        '$urlRouterProvider',

        function($routeProvider, $locationProvider, $controllerProvider, $compileProvider, $filterProvider, $provide, $stateProvider, $urlRouterProvider){

            if(config.defaultRoutePath !== undefined){
                $urlRouterProvider.otherwise(config.defaultRoutePath);
            }        
            app.controller = $controllerProvider.register;
            app.directive  = $compileProvider.directive;
            app.filter     = $filterProvider.register;
            app.factory    = $provide.factory;
            app.service    = $provide.service;
            
            if(config.routes !== undefined){
                angular.forEach(config.routes, function(route, path){
                    if(route.dependencies == undefined || route.dependencies == null){
                        //基于只加载模版的情况做了改良
                       $stateProvider.state(path,{
                            url: path,
                            templateUrl: route.templateUrl
                       });
                        
                    }else{
                        $stateProvider.state(path,{
                            url: path,
                            templateUrl: route.templateUrl,
                            resolve:dependencyResolverFor(route.dependencies)
                       });
                    }
                });
            }                                  
    }]).controller('AppCtrl', [
        '$scope', '$location', function($scope, $location) {
            $scope.main = {
                brand: '英语谐音记忆可视化'
            };         
        }
    ]);
    return app;
});